package br.com.Opet.PIM.Persistencia;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class ConnectionManager {

	private static Connection connection;
	
	private static String driver;
	
	private static String url;
	
	private static String usuario;
	
	private static String senha;

	public ConnectionManager() {
		try {
			Properties config = new Properties();
			String arquivo = "C:\\aplic\\banco.properties";
			config.load(new FileInputStream(arquivo));
			driver = config.getProperty("driver");
			url = config.getProperty("url");
			usuario = config.getProperty("usuario");
			senha = config.getProperty("senha");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws Exception {
		Class.forName(driver);
		connection = DriverManager.getConnection(url, usuario, senha);
		return connection;
	}
}
